package communication.server.vertx.handler.usermodule;

import communication.common.business.base.CommonBaseHandler;
import communication.common.business.base.FcrSocketAddress;
import communication.common.business.base.MethodMap;
import communication.common.business.user.request.LoginRequest;
import communication.common.business.user.request.RegistryRequest;
import communication.common.business.user.response.UserLoggedInfo;
import communication.common.business.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 用户模块
 * @author mac
 */
@Slf4j
@Component
public class UserModuleHandler extends CommonBaseHandler {

    @Autowired
    private UserService userService;


    @PostConstruct
    private void init() throws Exception {

        // 注册用户 (method定义，requestClassList必须与method的形参列表完全一致 )
        MethodMap registry=MethodMap.builder()
                .op("registry")
                .type(0)
                .serviceBean(userService)
                .methodName("registry")
                .requestClassList(new Class[]{RegistryRequest.class})
                .responseClass(null)
                .build();

        addMethodMap(registry);

        // 用户登录
        MethodMap loginByAccountName=MethodMap.builder()
                .op("loginByAccountName")
                .type(0)
                .serviceBean(userService)
                .methodName("loginByAccountName")
                .requestClassList( new Class[]{LoginRequest.class, FcrSocketAddress.class})
                .responseClass(UserLoggedInfo.class)
                .build();

        addMethodMap(loginByAccountName);

    }

    @Override
    public String getModuleName() {
        return "user";
    }
}
